﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace guest_management_in_a_hotel
{
    public partial class FrmQuanLyPhong : Form
    {
        SqlConnection conn;
        SqlCommand cmd;
        SqlDataAdapter da;
        DataSet ds;
        public static String sophong1,ghichu,tinhtrang,gia,kieuphong;
        public FrmQuanLyPhong()
        {
            InitializeComponent();
        }

        private void FrmQuanLyPhong_Load(object sender, EventArgs e)
        {
            try
            {
                conn = Connect.getConnection();
                conn.Open();
                String strSql = "select Room_Number[Số Phòng],Room_Description[Ghi Chú],status[Tình Trạng],Price_Per_Day[Giá / Ngày],Room_Type[Kiểu Phòng] from TblRooms order by Room_Type asc";
                cmd = new SqlCommand(strSql, conn);
                da = new SqlDataAdapter(cmd);
                ds = new DataSet();
                da.Fill(ds, "phong");
                dgvQLphong.DataSource = ds.Tables[0];
                conn.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex.Message);
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (cmbLoaiPhong.Text == "Tất cả")
            {
                try
                {
                    conn = Connect.getConnection();
                    conn.Open();
                    String strSql = "select Room_Number[Số Phòng],Room_Description[Ghi Chú],status[Tình Trạng],Price_Per_Day[Giá / Ngày],Room_Type[Kiểu Phòng] from TblRooms order by Room_Type asc";
                    cmd = new SqlCommand(strSql, conn);
                    da = new SqlDataAdapter(cmd);
                    ds = new DataSet();
                    da.Fill(ds, "phong");
                    dgvQLphong.DataSource = ds.Tables[0];
                    conn.Close();

                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error " + ex.Message);
                }
            }
            else
            {
                try
                {
                    conn = Connect.getConnection();
                    conn.Open();
                    String strSql = "select Room_Number[Số Phòng],Room_Description[Ghi Chú],status[Tình Trạng],Price_Per_Day[Giá / Ngày],Room_Type[Kiểu Phòng] from TblRooms where Room_Type like N'%" + cmbLoaiPhong.Text + "%'";
                    cmd = new SqlCommand(strSql, conn);
                    da = new SqlDataAdapter(cmd);
                    ds = new DataSet();
                    da.Fill(ds, "phong");
                    dgvQLphong.DataSource = ds.Tables[0];
                    conn.Close();

                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error " + ex.Message);
                }
            }
            
        }

        private void btnDK_Click(object sender, EventArgs e)
        {
            string status = dgvQLphong.CurrentRow.Cells[2].Value.ToString();
            string sophong = dgvQLphong.CurrentRow.Cells[0].Value.ToString();
            if (status == "đang sử dụng")
            {
                MessageBox.Show("Phòng này đã có người thuê. Xin mời chọn phòng khác");
            }
            else
            {
                sophong1 = dgvQLphong.CurrentRow.Cells[0].Value.ToString();
                ghichu = dgvQLphong.CurrentRow.Cells[1].Value.ToString();
                tinhtrang = dgvQLphong.CurrentRow.Cells[2].Value.ToString();
                gia = dgvQLphong.CurrentRow.Cells[3].Value.ToString();
                kieuphong = dgvQLphong.CurrentRow.Cells[4].Value.ToString();
                FrmDangky frmdk = new FrmDangky();
                frmdk.Show();
                this.Hide();
            }
        }

        private void btndkcancel_Click(object sender, EventArgs e)
        {
            FrmMain frmMain = new FrmMain();
            frmMain.Show();
            this.Hide();
        }


    }
}
